package org.wj.problem

import org.wj.problem.InorderTraversal.TreeNode

object IsValidBST {

  def main(args: Array[String]): Unit = {
    val root = new TreeNode(10)
    val left = new TreeNode(5)
    val right = new TreeNode(15)
    val rightLeft = new TreeNode(6)
    val rightRight = new TreeNode(20)

    root.left = left
    root.right = right
    right.left = rightLeft
    right.right = rightRight

    println(isValidBST(root))

  }


  def isValidBST(root: TreeNode): Boolean = {
    if(root==null) return true
    if(root.left == null&&root.right==null) return true
    if(root.left!=null && root.left.value>=root.value) return false
    if(root.right!=null && root.right.value<=root.value) return false
    isValidBST(root.left)&& isValidBST(root.right)
  }

  def isValidBST(childNode:TreeNode, rootVal:Int):Boolean = {
      true
  }

}
